package com.huawei.hms.framework.network.grs.a;

import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.framework.common.PLSharedPreferences;
import com.huawei.hms.framework.network.grs.c.b;
import java.util.Map;

public class c {
    private static final String a = c.class.getSimpleName();
    private static PLSharedPreferences b = null;

    public static class a {
        static final c a = new c();
    }

    private c() {
        b = new PLSharedPreferences(b.a(), "share_pre_grs_conf");
        e();
    }

    public static c a() {
        return a.a;
    }

    private void e() {
        try {
            String l = Long.toString((long) b.a().getPackageManager().getPackageInfo(b.a().getPackageName(), 0).versionCode);
            if (!l.equals(a("version", ""))) {
                Logger.v(a, "app version changed! old version{%s} and new version{%s}", a("version", ""), l);
                c();
                b("version", l);
            }
        } catch (Throwable e) {
            Logger.w(a, "get app version failed and catch NameNotFoundException", e);
        }
    }

    public String a(String str, String str2) {
        return b.getString(str, str2);
    }

    public void a(String str) {
        b.remove(str);
    }

    public String b() {
        return a("cp", "");
    }

    public void b(String str, String str2) {
        b.putString(str, str2);
    }

    public void c() {
        b.clear();
    }

    public Map<String, ?> d() {
        return b.getAll();
    }
}
